package bitbot.md.bitstamp;

import java.io.IOException;

import bitbot.core.BaseDataFetcher;
import bitbot.md.Pair;
import bitbot.md.TimeAndSales;

import com.google.gson.Gson;

public class BitstampDataFetcher extends BaseDataFetcher {
	
	private final static String URL = "https://bitstamp.net";

	private static String cid;
	private static String k;
	private static String s;
	
	
	public BitstampDeepData getDeep() throws IOException {
		String url = URL + "/api/order_book/";
		String jsonString = fetchPublicDataString(url);
        Gson gson = new Gson();
        BitstampDeepData deep = gson.fromJson(jsonString, BitstampDeepData.class);
        return deep;
	}
	
	
	public TimeAndSales getTimeAndSales() throws IOException {
		String url = URL + "/api/transactions/";
		String jsonString = fetchPublicDataString(url);
		
		Gson gson = new Gson();
		BitstampTimeAndSale[] tos = gson.fromJson(jsonString, BitstampTimeAndSale[].class);
		BitstampTimeAndSalesData data = new BitstampTimeAndSalesData(tos, System.currentTimeMillis());
		//[{"date": "1392839750", "tid": 3608631, "price": "635.98", "amount": "0.65900000"},...]
        return data.convert(Pair.BTC_USD);
	}
		
}
